/**
 * @file:          main.c
 * @brief:
 * @details:
 * @author:        wjh
 * @date created:  2023.06.07
 * @version:       1.0.0
 * @par Copyright (c):
 *
 * @par History (desc):
 *   version:1.0.0, wjh, 2023.06.07,16:52:06
 */

/* Include files **************************************************************/
// #include "StepperMotorController.h"
#include "DefaultParam.h"
#include "main.h"
#include "stdio.h"
#include "common.h"
#include "base_math.h"
#include "ConfigOption.h"
// #include "STC32G8K64.h"
#include "ch32v30x_module.h"

int main(int argc, char const *argv[])
{
    // DefaultParam_Init(&stepper_motor_controller);
    stepper_motor_controller.ConfigParam(&stepper_motor_controller);
    stepper_motor_controller.Init(&stepper_motor_controller);

    while (1)
    {
#ifdef HARDWARE_DISABLE
        stepper_motor_controller.driver_board->param_pwm_output_en = TRUE;
        stepper_motor_controller.controller->param_en_all_control_switch = 1;
        stepper_motor_controller.ControlLoop(&stepper_motor_controller);
        stepper_motor_controller.TimTask(&stepper_motor_controller);
#else
        // while (!(stepper_motor_controller.isr_run_num > 0))
        while (stepper_motor_controller.timer_section_num != 0 || stepper_motor_controller.run_start == 0)
        {
            /* code */
            __asm volatile ("");
        }

        // if (stepper_motor_controller.isr_run_num > 0)
        // {
        /* timming measuring gpio set*/
        // stepper_motor_controller.driver_board->TestGpio_Set(stepper_motor_controller.driver_board);
        stepper_motor_controller.isr_run_num = 0;
        stepper_motor_controller.run_start = 0;

        stepper_motor_controller.ControlLoop(&stepper_motor_controller);
        
        // WAIT_UNTIL_TIME_SECTION((&stepper_motor_controller), stepper_motor_controller.n_multiple_of_timmer_tick-1);
        // WAIT_UNTIL_TIME_SECTION((&stepper_motor_controller), 2);
        /* timming measuring gpio set*/
        stepper_motor_controller.driver_board->TestGpio_Reset(stepper_motor_controller.driver_board);
        // }

        // if (stepper_motor_controller.encoder_calibration_en == 0 && stepper_motor_controller.isr_run_num > 1)
        // {
        // stepper_motor_controller.isr_run_num = 0;
        // DBprintf("--over_time:[%d]\r\n", stepper_motor_controller.isr_run_num);
        // DBprintf("--");
        // }
#endif
    }

    return 0;
}

void UartReceiveDataProcessing(uint8 receive_byte)
{
    // stepper_motor_controller.communication_interface.ReceiveDataPack(&stepper_motor_controller.communication_interface,
    //                                                                         receive_byte);

    // stepper_motor_controller.communication_interface.ReceiveDataPackWithoutProtocol(&stepper_motor_controller.communication_interface, receive_byte);
}

void UartSendDataProcessing()
{
}
